package com.hu.bgp.server;

import java.util.Hashtable;
import java.util.Iterator;

import com.hu.bgp.exceptions.CommonException;

/**
 * Een collectie van gametypes.
 * 
 * @author ejvos
 */
public class GameTypeCollection implements Iterable<GameType>
{
	private Hashtable<String, GameType> collection = new Hashtable<String, GameType>();

	public GameType getByAlias(String alias)
	{
		GameType ret = collection.get(alias);
		if (ret == null)
		{
			throw new CommonException("GameType not found");
		}
		return ret;
	}

	public void add(GameType gameType)
	{
		System.out.println("GameTypeCollection.add: " + gameType.getAlias());
		if (collection.contains(gameType.getAlias()))
		{
			throw new CommonException("GameType already excists!");
		}
		collection.put(gameType.getAlias(), gameType);
	}

	public Iterator<GameType> iterator()
	{
		return collection.values().iterator();
	}
}
